package cn.scy.util.xiamdx;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

@Component
@Slf4j
public class MD5 {

    public static String makeMD5(String plainText) {
        String re_md5 = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes(StandardCharsets.UTF_8));
            byte[] b = md.digest();
            int i;
            StringBuffer buf = new StringBuffer();
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            re_md5 = buf.toString().toLowerCase();
        } catch (NoSuchAlgorithmException ignored) {}
        return re_md5;
    }

    public static String makeMD5(String... strs) {
        return makeMD5(String.join("", strs));
    }
    public static boolean checkMD5(String sign, String... strs) {
        log.info("加密后密钥："+makeMD5(strs));
        return StrUtil.equals(sign, makeMD5(strs));
    }

    public static void main(String[] args) {
        String requestTime = "2024-06-05 10:30:00";
        String uuid = String.valueOf(UUID.randomUUID());
        System.out.println(uuid);
        System.out.println(makeMD5("O13500329202409301376","123","2024-09-30 14:07:00"));

    }
}
